package com.heima.controller;

import com.heima.entity.TbTask;
import com.heima.pojo.vo.StatusTopVo;
import com.heima.service.ITbTaskService;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

@Slf4j
@RestController
@RequestMapping("/api/status-service")
public class StatusTop {

    @Autowired
    private ITbTaskService iTbTaskService;

    @GetMapping("/status/top10")
    public List<StatusTopVo> getStatusTop(){
        List<TbTask> tbTaskList = iTbTaskService.lambdaQuery()
                .eq(TbTask::getProductTypeId, 3)
                .list();
        List<StatusTopVo> statusTopVoList = tbTaskList.stream().map(tbTask -> {
            StatusTopVo statusTopVo = new StatusTopVo();
            statusTopVo.setInnerCode(tbTask.getInnerCode());
            statusTopVo.setAddress(tbTask.getAddr());
            statusTopVo.setTime(tbTask.getCreateTime().toString());

            return statusTopVo;
        }).collect(Collectors.toList());
        return statusTopVoList;
    }
}
